package com.ctshk.sapp.train.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.annotations.Authority;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.train.dto.TrainNumberConditionListDTO;
import com.ctshk.rpc.train.dto.TrainNumberDTO;
import com.ctshk.rpc.train.dto.TrainNumberListDTO;
import com.ctshk.rpc.train.dto.TrainStopStationDTO;
import com.ctshk.rpc.train.req.TrainNumberPageReq;
import com.ctshk.rpc.train.req.TrainNumberQueryReq;
import com.ctshk.rpc.train.req.TrainNumberReq;
import com.ctshk.rpc.train.service.CJTrainProductService;
import com.ctshk.rpc.train.service.ITrainNumberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 火车车次表 前端控制器
 * </p>
 *
 * @author 彭柳霖
 * @since 2021-03-10
 */
@Api(value="资源中心-火车车次管理", tags="资源中心-火车车次管理")
@RestController
@RequestMapping("/train-number")
public class TrainNumberController extends BaseController {

    @DubboReference
    private ITrainNumberService trainNumberService;

    @DubboReference
    private CJTrainProductService cjTrainProductService;

    @ApiOperation(value="火车车次分页查询列表", notes="火车车次分页查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "火车车次分页查询列表", operDesc = "火车车次分页查询列表")
    @PostMapping("/list")
    @Authority
    public Result<PageResponse<TrainNumberListDTO>> queryTrainNumberList(@RequestBody TrainNumberPageReq req) {
        PageResponse<TrainNumberListDTO> response = trainNumberService.queyList(req);
        return Result.success(response);
    }

    @ApiOperation(value="新增火车车次", notes="新增火车车次")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.ADD, operTitle = "新增火车车次", operDesc = "新增火车车次")
    @PostMapping("/save")
    public Result saveTrainNumber(@RequestBody @Valid TrainNumberReq trainNumberReq) {
        TokenUser user = getCurrentUser(getRequest());
        return trainNumberService.saveTrainNumber(trainNumberReq,user);
    }

    @ApiOperation(value="修改火车车次", notes="修改火车车次")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "修改火车车次", operDesc = "修改火车车次")
    @PostMapping("/update")
    public Result updateTrainNumber(@RequestBody @Valid TrainNumberReq trainNumberReq) {
        TokenUser user = getCurrentUser(getRequest());
        return trainNumberService.updateTrainNumber(trainNumberReq,user);
    }

    @ApiOperation(value = "查询火车车次详情", notes = "查询火车车次详情")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "编辑时查询火车车次详情", operDesc = "编辑时查询火车车次详情")
    @GetMapping(value = "/detail")
    public Result<TrainNumberDTO> queryDetail(@RequestParam(value = "id", required = true) Long id) {
        return Result.success(trainNumberService.queryDetail(id));
    }

    @ApiOperation(value = "火车车次有效无效设置", notes = "火车车次有效无效设置")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.UPDATE, operTitle = "火车车次有效无效设置", operDesc = "火车车次有效无效设置")
    @GetMapping("/isValid/{id}")
    public Result isValid(@PathVariable("id") Long id){
        TokenUser user = getCurrentUser(getRequest());
        return trainNumberService.isValid(id,user);
    }


    @ApiOperation(value = "根据铁路公司查询火车车次信息", notes = "根据铁路公司查询火车车次信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "根据巴士公司查询巴士路线", operDesc = "根据巴士公司查询巴士路线")
    @PostMapping(value = "/queryLine")
    public Result<List<TrainNumberDTO>> queryLine(@RequestBody @Valid TrainNumberQueryReq trainNumberQueryReq) {
        return Result.success(trainNumberService.queryTrainNumber(trainNumberQueryReq));

    }

    @ApiOperation(value = "根据车次id查询火车经停站信息", notes = "根据车次id查询火车经停站信息")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "根据车次id查询火车经停站信息", operDesc = "根据车次id查询火车经停站信息")
    @GetMapping(value = "/queryStopStaionByTrainId")
    public Result<List<TrainStopStationDTO>> queryStopStaionByTrainId(@RequestParam(value = "trainId", required = true) Long trainId) {
        return Result.success(trainNumberService.queryStopStaionByTrainId(trainId));

    }

    @ApiOperation(value="火车车次模糊搜素查询列表", notes="火车车次模糊搜素查询列表")
    @OperationLogAnnotation(operModul = OperationLogModel.TICKET, operType = OperationLogType.QUERY, operTitle = "火车车次模糊搜素查询列表", operDesc = "火车车次模糊搜素查询列表")
    @PostMapping("/conditionList")
    public Result<PageResponse<TrainNumberConditionListDTO>> queryTrainNumberConditionList(@RequestBody TrainNumberPageReq req) {
        PageResponse<TrainNumberConditionListDTO> response = trainNumberService.queryTrainNumberConditionList(req);
        return Result.success(response);
    }
}
